package com.ruoyi.zuzhi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zuzhi.domain.AddressListVo;
import com.ruoyi.zuzhi.service.IAddressListVoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 通讯录Controller
 * 
 * @author lgr
 * @date 2025-05-29
 */
@RestController
@RequestMapping("/zuzhi/addressList")
public class AddressListVoController extends BaseController
{
    @Autowired
    private IAddressListVoService addressListVoService;

    /**
     * 查询通讯录列表
     */
    @PreAuthorize("@ss.hasPermi('zuzhi:addressList:list')")
    @GetMapping("/list")
    public TableDataInfo list(AddressListVo addressListVo)
    {
        System.out.println(addressListVo);
        startPage();
        List<AddressListVo> list = addressListVoService.selectAddressListVoList(addressListVo);
        return getDataTable(list);
    }

    /**
     * 导出通讯录列表
     */
    @PreAuthorize("@ss.hasPermi('zuzhi:addressList:export')")
    @Log(title = "通讯录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AddressListVo addressListVo)
    {
        List<AddressListVo> list = addressListVoService.selectAddressListVoList(addressListVo);
        ExcelUtil<AddressListVo> util = new ExcelUtil<AddressListVo>(AddressListVo.class);
        util.exportExcel(response, list, "通讯录数据");
    }

    /**
     * 获取通讯录详细信息
     */
    @PreAuthorize("@ss.hasPermi('zuzhi:addressList:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(addressListVoService.selectAddressListVoById(id));
    }

    /**
     * 新增通讯录
     */
    @PreAuthorize("@ss.hasPermi('zuzhi:addressList:add')")
    @Log(title = "通讯录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddressListVo addressListVo)
    {
        return toAjax(addressListVoService.insertAddressListVo(addressListVo));
    }

    /**
     * 修改通讯录
     */
    @PreAuthorize("@ss.hasPermi('zuzhi:addressList:edit')")
    @Log(title = "通讯录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AddressListVo addressListVo)
    {
        return toAjax(addressListVoService.updateAddressListVo(addressListVo));
    }

    /**
     * 删除通讯录
     */
    @PreAuthorize("@ss.hasPermi('zuzhi:addressList:remove')")
    @Log(title = "通讯录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(addressListVoService.deleteAddressListVoByIds(ids));
    }

    //更新部门
    @PreAuthorize("@ss.hasPermi('zuzhi:addressList:edit')")
    @Log(title = "通讯录", businessType = BusinessType.UPDATE)
    @PutMapping("/updateDept")
    public AjaxResult updateDept(@RequestBody AddressListVo addressListVo) {
        return toAjax(addressListVoService.updateDept(addressListVo));
    }
}
